﻿<%@ Page Title="城市物流设置" Language="C#" MasterPageFile="~/master/m.master" %>

<script runat="server"></script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <link href="../assets/css/shelf/base.css" rel="stylesheet">
    <link href="../assets/css/plugins/iCheck/customsmall.css" rel="stylesheet" />
    <link href="../assets/css/plugins/webuploader/webuploader.css" rel="stylesheet" />
    <style type="text/css">
        .condition {
            padding: 2px 0;
        }

        .footable-odd {
            border-color: darkgray;
        }
    </style>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="main" runat="Server">
    <div class="system-box">
        <div class="right-side">
            <div class="btns-container">
                <div class="modal inmodal" id="addWindow" tabindex="-1" role="dialog" aria-hidden="true">
                </div>
            </div>

            <div class="condition">
                <label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;省份:</label>
                <select class="form-control input-w160" id="search-province">
                    <option value="">请选择</option>
                </select>
                <label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;城市:</label>
                <select class="form-control input-w160" id="search-city">
                    <option value="">请选择</option>
                </select>
            </div>
            <div class="condition-title">&nbsp;&nbsp;&nbsp;参数设置</div>
            <div class="condition">
                <label>物流天数:</label>
                <input class="form-control input-w160" id="transfer-days" placeholder="输入天数" />
            </div>
            <div class="right-content-box">
                <div class="ibox-content">
                    <table class="footable table table-stripped">
                        <thead></thead>
                        <tbody id="pageList"></tbody>
                    </table>
                </div>
            </div>

            <div class="pageControl"></div>
        </div>
    </div>

</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="footer" runat="Server">
    <script src="../assets/js/page/pageControl.js"></script>
    <script src="../assets/js/page/rScroll.js"></script>
    <script src="../assets/js/page/tableControl.js"></script>
    <script src="../assets/js/plugins/webuploader/webuploader.min.js"></script>
    <script src="../assets/js/framework.js?1"></script>
    <script src="../assets/js/plugins/iCheck/icheck.min.js"></script>
    <script src="../assets/js/plugins/iCheck/icheckAll.js"></script>
    <script>
        $('document').ready(function () {
            //模块ID
            var ModuleID = Y.getUrlParam("ModuleID");
            //当前页数
            var page = 1;
            commonUtil.loadBtnList(ModuleID, function () {
                $('#editBtn').attr("disabled", "disabled");
                $('#deleteBtn').attr("disabled", "disabled");
                rScroll();
            });

            //加载省份
            var provinceList = [];
            var proName = '';
            Y.API2('OdsErpBasArea', 'GetAllOdsErpBasAreaList', {}, function (data) {
                if (data.Success == false) {
                    swal(data.Message, '', 'error');
                } else {
                    data.map(function (item) {
                        $('#search-province').append('<option value="' + item[0].ParentID + '">' + item[0].ParentName + '</option>');
                        $('#province').append('<option value="' + item[0].ParentID + '">' + item[0].ParentName + '</option>');
                        var tempList = [];
                        item.map(function (it) {
                            tempList.push({
                                AreaID: it.AreaID,
                                AreaName: it.AreaName
                            })
                        })
                        provinceList.push({
                            ParentID: item[0].ParentID,
                            ParentName: item[0].ParentName,
                            List: tempList
                        })
                    })
                }
            })

            //省份变更
            var changeProvince = function (pEl, cEl) {
                var value = pEl.val();
                cEl.html('<option value="">请选择</option>');
                if (value == '')
                    return false;
                var html = '';
                provinceList.map(function (item) {
                    if (item.ParentID == value) {
                        item.List.map(function (it) {
                            html += '<option value="' + it.AreaID + '">' + it.AreaName + '</option>';
                        })
                        cEl.append(html);
                        return false;
                    }
                })
            }
            $('#search-province').change(function () {
                changeProvince($(this), $('#search-city'));
            })
            $('#province').change(function () {
                changeProvince($(this), $('#city'));
            })

            var dataList = [];
            //处理表头
            if ($('.footable thead').children().size() == 0) {
                tableControl.initThead('.footable',
                    [
                        {
                            trClass: '',
                            children: [
                                { tdText: '', c: 0, r: 0, tdHtml: '<input type="checkbox" id="checkAllPlan" />', tdId: '', tdClass: 'diy-td-w50' },
                                { tdText: '发货城市', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'diy-td-w150' },
                                { tdText: '到达城市', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'diy-td-w150' },
                                { tdText: '物流天数', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'ddiy-td-w150' },
                            ]
                        }
                    ]);
            }

            var pageList = [];
            //获取列表
            var loadList = function () {
                $('#editBtn').attr('disabled', 'disabled');
                $('#deleteBtn').attr('disabled', 'disabled');
                //debugger;
                pageControl.init('CityLogisticsSettings', 'GetList', {
                    keys: $('#search-city').val(),
                    Page: page,
                    Size: 50,
                    needLayer: true,
                    alwaysCallBack: function () {
                        $('#pageList').empty();
                    }
                }, function (result) {
                    //debugger;
                    pageList = [];
                    page = result.page;
                    var tBody = [];
                    if (!Y.checkNull(result.data)) {
                        if (result.data.Items.length > 0) {
                            var IsEmpty = '0';
                            result.data.Items.map(function (items, i) {
                                var tempChild = [];

                                tempChild.push({ tdText: '', c: 0, r: 0, tdHtml: '<input type="checkbox" class="checkPlan" />', tdId: '', tdClass: '' });
                                tempChild.push({
                                    tdText: '', c: 0, r: 0,
                                    tdHtml: '<span style="display:inline-block; width:150px;">' +
                                    (items.ShipCity || IsEmpty) +
                                    '</span>',
                                    tdId: '', tdClass: 'ShipCity'
                                });
                                tempChild.push({
                                    tdText: '',
                                    c: 0,
                                    r: 0,
                                    tdHtml: '<span style="display:inline-block; width:150px;">' + (items.ReceivingCity || IsEmpty) + '</span>',
                                    tdId: '',
                                    tdClass: 'ReceivingCity'
                                });
                                tempChild.push({
                                    tdText: '',
                                    c: 0,
                                    r: 0,
                                    tdHtml: '<span style="display:inline-block; width:150px;">' + (items.TransDays || IsEmpty) + '</span>',
                                    tdId: '',
                                    tdClass: 'TransDays'
                                });
                                tempChild.push({
                                    tdText: '',
                                    c: 0,
                                    r: 0,
                                    tdHtml: '<span style="display:inline-block; width:150px">' + (items.AreaIDBg || IsEmpty) + '</span>',
                                    tdId: '',
                                    tdClass: 'AreaIDBg hide'
                                });
                                tempChild.push({
                                    tdText: '',
                                    c: 0,
                                    r: 0,
                                    tdHtml: '<span style="display:inline-block; width:50px">' + (items.AreaIDEnd || IsEmpty) + '</span>',
                                    tdId: '',
                                    tdClass: 'AreaIDEnd hide'
                                }); tempChild.push({
                                    tdText: '',
                                    c: 0,
                                    r: 0,
                                    tdHtml: '<span style="display:inline-block; width:50px">' + (items.CompanyID || IsEmpty) + '</span>',
                                    tdId: '',
                                    tdClass: 'CompanyID hide'
                                });
                                var tempTr = {
                                    trClass: (i % 2 == 0 ? 'gradeX footable-even' : 'gradeX footable-odd') + ' ' + i,
                                    children: tempChild
                                };
                                tBody.push(tempTr);
                            });
                        }
                        rScroll();
                    }
                    tableControl.initTbody('.footable', (tBody.length > 0 ? tBody : null), 13, null);
                    $(".footable").icheckAll({
                        checkObj: ".checkPlan",//表格下面的选择控件对象 选择器
                        checkAllObj: "#checkAllPlan",//全选 选择器
                        clickoutBoxCheck: true,//点击行 不选中
                        checkboxMargin: "4px 0 0 0 "//上右下左
                    });
                });
            }



            //选中记录
            $('#pageList').on('click',
                'tr',
                function () {

                    $('.footable tr').removeClass('check');

                    var trClass = $(this).attr("class");
                    trClass = trClass.replace(/gradeX /, "");
                    trClass = trClass.replace(/footable-even /, "");
                    trClass = trClass.replace(/footable-odd /, "");
                    trClass = '.' + trClass;
                    $(trClass).addClass("check");

                });

            //查询按钮
            $('.btns-container').on('click', '#btn-search', function () {
                page = 1;
                loadList();
            });

            //保存按钮
            $('.btns-container').on('click', '#btn-save', function () {

                if (Y.checkNull($("#transfer-days").val())) {
                    swal('请先输入要设置的物流天数');
                    return false;
                }
                if ($("#transfer-days").val() < 0) {
                    swal('物流天数不能小于0');
                    return false;
                }

                if (!$(".footable").find('.checkPlan').is(':checked')) {
                    swal('请先勾选要保存的项');
                    return false;
                }
                var CheckedList = [];
                var LogisticsDays = $("#transfer-days").val();
                $(".footable").find('.checked').each(function () {
                    var CompanyID = $(this).parents("td").siblings(".CompanyID").text();
                    var AreaIDBg = $(this).parents("td").siblings(".AreaIDBg").text();
                    var AreaIDEnd = $(this).parents("td").siblings(".AreaIDEnd").text();
                    CheckedList.push({
                        CompanyID: CompanyID,
                        AreaIDBg: AreaIDBg,
                        AreaIDEnd: AreaIDEnd
                    });
                });

                layer.msg('玩命加载中……', { icon: 16, shade: 0.5, time: 0, maxWidth: 200 });
                Y.API2('CityLogisticsSettings', 'Save', {
                    CheckedList: CheckedList,
                    LogisticsDays: LogisticsDays
                }, function (data) {
                    layer.closeAll('dialog');
                    if (data.Success == false) {
                        swal(data.Message, '', 'error');
                    } else {
                        swal('保存成功', '', 'success');
                        loadList();
                    }
                });
            });

            //导入
            $(".btns-container").on("click", '#importBtn', function () {
                $.ImportExcelTemplate({
                    filetype: ['CITYLOGISTICSSETTINGS'],
                    filename: [
                        { name: '城市间物流天数', state: null }
                    ],
                    action: 'ImportTemplate',
                    after: function () {
                        //回调方法
                        console.log("本次导入结束时间：" + new Date());
                        loadList();
                    }
                });
            });


            loadList();
        });




    </script>
</asp:Content>
